#pragma once
#include <vector>
#include "d3dUtil.h"
#include "ObjectTypes.h"

#define MESHMANAGER MeshManager::Instance()

// data for a mesh. A mesh pointer along with
// a list of materials and textures
struct MeshData
{
	ID3DXMesh *mesh;
	std::vector<Mtrl> *materialList;
	std::vector<IDirect3DTexture9*> *textureList;
	ObjectType objectType;
};

// data for a buffered object with a vertex
// buffer, an index buffer, a material and
// a texture
struct BufferData
{
	IDirect3DVertexBuffer9	*vbuffer;
	IDirect3DIndexBuffer9	*ibuffer;
	Mtrl					*mtrl;
	IDirect3DTexture9		*texture;
	ObjectType objectType;
};

// Meshmanager which holds data for all game meshes
// so we only need to load them in once. Every game
// object should query the MeshManager for the mesh it
// wants during its render function.
class MeshManager
{
private:
	// private constructors
	MeshManager(void);
	MeshManager(const MeshManager&);
	MeshManager* operator=(const MeshManager&);
	~MeshManager(void);

protected:
	// storage of mesh and buffer information
	std::vector<MeshData*> meshData;
	std::vector<BufferData*> bufferData;

public:
	// returns MeshData to the object asking for it, identified
	// by numerical value
	MeshData* GetMesh(ObjectType objectType);

	// returns BufferData to the object asking for it, identified
	// by numerical value.
	BufferData* GetBuffer(ObjectType objectType);

	// loads the given mesh into meshData
	void LoadMesh(const std::string& filename, ObjectType objectType);
	void LoadMesh(ID3DXMesh* mesh, Mtrl mtrl, IDirect3DTexture9* texture, ObjectType objectType);

	// adds the pre-created buffer to the list of buffer objects
	void AddBuffer(IDirect3DVertexBuffer9* vbuffer, IDirect3DIndexBuffer9* ibuffer, Mtrl *mtrl, IDirect3DTexture9 *texture, ObjectType objectType);

	// delete all information
	void ClearAll(void);

	// accessing the singleton
	static MeshManager* Instance();
};